import java.util.Stack;


public class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minstack;
    public MinStack() {
        this.stack=new Stack<>();
        this.minstack=new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()||val<=minstack.peek()){
            minstack.push(val);
        }

    }

    public void pop() {
        if(minstack.peek().equals(stack.peek())){
            minstack.pop();
        }
        stack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minstack.peek();
    }
}
